//
//  ChosePrivinceViewController.m
//  u76ho
//
//  Created by m-air-01 on 16/1/10.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "ChosePrivinceViewController.h"
#import "MineFirCell.h"
#import "PositionModel.h"
#import "ChooseSectionViewController.h"
@interface ChosePrivinceViewController ()
<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * _tableView;
    NSMutableArray * dataSource;
}
@end

@implementation ChosePrivinceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self main];
    self.navigationItem.title = @"选择省份";
   // [self addBackItem];
    //[self addNavgationBar];
    // Do any additional setup after loading the view.
}
-(void)main
{
    dataSource = [[NSMutableArray alloc]init];
    self.view.backgroundColor = [UIColor whiteColor];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MineFirCell" bundle:nil] forCellReuseIdentifier:@"MineFirCell"];
    [self.view addSubview:_tableView];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self requestData];
}
-(void)requestData
{
    
    [U76HONet selectedTypeReadWithtype:@"1" fid:@"0" code:@"0" andDataBlock:^(NSArray *arr) {
        NSLog(@"地区分类获取数据成功了");
        [dataSource addObjectsFromArray:arr];
        [_tableView reloadData];
    }];
}

#pragma mark - _tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineFirCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MineFirCell"];
    PositionModel * model = dataSource[indexPath.row];
    cell.contentLab.text = model.typenames;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 33) {
        cell.isHidden = @"yes";
    }
    if (indexPath.row == 32) {
        cell.isHidden = @"yes";
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PositionModel * model = dataSource[indexPath.row];
    
    if (indexPath.row == 32 || indexPath.row == 33) {
        [self.delegate selectePrivince:model.allname andids:model.Ids withTag:_tag];
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        
        ChooseSectionViewController * chooseSectoinVC = [[ChooseSectionViewController alloc]init];
        chooseSectoinVC.fid = model.Code;
        chooseSectoinVC.code = model.Typeid;
        chooseSectoinVC.tag = _tag;
        if (indexPath.row == 31) {
            chooseSectoinVC.isEnd = YES;
        }
        chooseSectoinVC.titleStr = model.typenames;
        [self.navigationController pushViewController:chooseSectoinVC animated:YES];
    }
}
#pragma  mark - 返回按钮图标
-(void)addBackItem{
    UIButton * backItem = [UIButton buttonWithType:UIButtonTypeCustom];
    backItem.frame = CGRectMake(0, 0, 9, 17);
    [backItem setImage:[UIImage imageNamed:@"返回图标"] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItem:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backItem];
}
-(void)backItem:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
